{% extends 'basepl.html' %}
{% load static %}
{% block head %}
    <title>作业</title>
    <style>
        #tjinput{
            border: rgba(56, 25, 169, 0.07) solid ;
            width: 480px;
            height: 420px;
            left: 7px;
            position: absolute;
            visibility: hidden;
        }
        .page{
        position: absolute;
        bottom: 10px;
        left: 30px;
    }
        #tjbtn{
            left: 120px;
            bottom: 10px;
            position: absolute;
        }
        #up{

                bottom: 10px;
                left: 185px;
                position: absolute;
        }
        #zuoyeshow{
            background-color: ghostwhite;
            border: rgba(56, 25, 169, 0.07) solid ;
            width: 500px;
            height: 590px;
            left: 0;
            position: relative;
        }
        #tjtext{
            font-size: 15px;
            font-family: 楷体;
            color: #666666;
        }
        .txt{
            width: 450px;
        }
    </style>
<script src="{% static '/jquery.min.js' %}"></script>
<script type="text/javascript" src='/static/tiny_mce/tiny_mce.js'></script>
<script type="text/javascript">
    tinyMCE.init({
        forced_root_block:'',
        'mode':'textareas',
        'theme':'advanced',
        'width':472,
        'height':360
    });
</script>
<script >
    function  getInputid(id) {

            $.get('/zuoyetj/ajax_tjstu?zytopic='+$('#'+id).val(),function (data) {
                $("#fbt").html(data['fbtext']).show();
                $('#fbtd').html(data['fbt']).show();
                $("#fenge").html('------------------------------------').show();
                if(data['tjtext']){
                    document.getElementById('tjinput').style.visibility="hidden";
                    $("#tjtime").html(data['tjtime']).show();
                    $("#tjtext").html(data['tjtext']).show();
                    if (data['filepath']){
                        var lk="/download?name="+data['filepath'];
                        $('.relink').attr('href',lk);
                        index = data['filepath'].lastIndexOf("\/");
                        var str  = data['filepath'].substring(index + 1, data['filepath'].length);
                        $('.relink').text(str);
                    }
                    else{
                        $('.relink').attr('href','#');
                        $('.relink').text('');

                    }
                }
                else if(data['filepath']) {
                    document.getElementById('tjinput').style.visibility = "hidden";
                    var lk="/download?name="+data['filepath'];
                    $('.relink').attr('href',lk);
                    index = data['filepath'].lastIndexOf("\/");
                    var str  = data['filepath'].substring(index + 1, data['filepath'].length);
                    $('.relink').text(str);
                    $("#tjtime").html(data['tjtime']).show();
                    $("#tjtext").html('').show();
                }else{
                    document.getElementById('tjinput').style.visibility="visible";
                    var top=document.getElementById('topic');
                    top.value=data['fbtext'];
                    $("#tjtext").html('').show();
                    $('.relink').attr('href','#');
                    $('.relink').text('');
                    $("#tjtime").html('').show();

                }

            })
    }
</script>
{% endblock head%}
{% block nav %}
<li><a href="/stuIndex">首页</a></li>
<li><a href="#top">大学课程教学过程管理系统</a></li>
<li><a href="/">切换账号</a></li>
<li><a href="#">&#9658;{{ request.session.cname }}&#9668;</a></li>
<li><a href="#">关于</a></li>
<li><a href="/">注销</a></li>
{% endblock nav %}
{% block li %}

    <li><a href="/stuIndex/stuTask/zuoyetj">作&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;业</a></li>
    <li><a href="/stuIndex/stuTask?cname={{ request.session.cname }}">讨&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;论</a></li>
    <li><a href="/stuIndex/stuTask?cname={{ request.session.cname }}">资&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;源</a></li>
{% endblock li %}

{% block section %}
<div id="zuoyeshow">
    <table id="detail"  cellpadding="3px">
        <tr>问题&#10151;提交时间&#10151;提交内容&#10151;附件<td id="fbt"></td></tr>
        <tr><td id="fbtd"></td></tr>
        <tr><td id="fenge"></td></tr>
        <tr ><td id="tjtime"></td></tr>
        <tr ><td id="tjtext"></td></tr>
        <tr><td id="filepath"><a class="relink" href="/download?name={{ foo.scfp }}">{{ foo.scfp }}</a></td></tr>
    </table>
    <form id="tjinput" method = 'post' enctype="multipart/form-data"  >
        {% csrf_token %}
        <textarea id="tjt" name="zy_text"></textarea>
        <input type="text" id="topic" name="ttopic" value="" hidden>

        <input type="file" id="up" name="zy_upload" value="浏览">
        <input id="tjbtn" type="submit" value = "提交" />

    </form>

</div>
<div id="gonggao">
    {% if fb_text %}


    <table id="show" cellpadding="2"   >
    {% for i in p %}
        <tr>
            <td>{{ forloop.counter }}</td>
            <td><input class="txt" type="button" id="input{{ i.zyid }}" value="{{ i.zytopic }}" onclick="getInputid(id)"></td>
        </tr>
    {% endfor %}
    </table>

        <div class="page">
        {% if p.has_previous %}
            <a href="/stuIndex/stuTask/zuoyetj/{{ p.previous_page_number}}">上一页</a>
        {% endif %}
            {% for foo in pg.page_range %}
                {% if foo == p.number %}
                    <a href="#">{{ foo }}</a>
                    {% else %}
                    <a href="/stuIndex/stuTask/zuoyetj/{{ foo }}">{{ foo }}</a>
                {% endif %}
            {% endfor %}
        {% if p.has_next %}
            <a href="/stuIndex/stuTask/zuoyetj/{{ p.next_page_number }}">下一页</a>
        {% endif %}
      </div>
    {% else %}
        <span>未发布过作业</span>
    {% endif %}

</div>
{% endblock section %}
